import 'package:flutter/material.dart';
import 'package:flutter_base/widgets/button/common_button.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_base/config/app_color.dart';

class CommonNormalSheet extends StatelessWidget {
  // const CommonNormalSheet({super.key});
  final String title;
  final String? message;
  final String? cancelText;
  final String? sureText;
  final VoidCallback? onCancel;
  final VoidCallback? onSure;

  // final Widget? cancelWidget;
  // final Widget? sureWidget;
  final bool showCancel;

  // final bool barrierDismissible;
  // final EdgeInsetsGeometry? margin;
  // final EdgeInsetsGeometry? padding;
  // final Decoration? decoration;
  // final Color? backgroundColor;
  final Widget? bodyWidget;

  //点击确定和取消是否关闭
  final bool autoDismiss;
  final String? nameSetting;
  final TextAlign? messageTextAlign;
  final TextStyle? titleTextStyle;
  final int titleMessagePadding;
  final Widget? topWidget;

  const CommonNormalSheet(
      {super.key,
      this.title = "",
      this.message,
      this.cancelText,
      this.sureText,
      this.onCancel,
      this.onSure,
      this.showCancel = true,
      // this.cancelWidget,
      // this.sureWidget,
      // this.barrierDismissible = true,
      this.autoDismiss = true,
      // this.padding,
      // this.margin,
      // this.decoration,
      // this.backgroundColor,
      this.bodyWidget,
      this.nameSetting,
      this.messageTextAlign,
        this.titleMessagePadding = 32,
        this.topWidget,
      this.titleTextStyle});

  static String name = 'CommonNormalSheet';

  Future<bool?> show() async {
    return await Get.bottomSheet(
      this,
      // barrierDismissible: barrierDismissible,
      // name: nameSetting ?? CommonNormalDialog.name,
      isScrollControlled: true,
      barrierColor: Colors.black.withOpacity(0.40),
      // transitionDuration: const Duration(milliseconds: 250),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 32.w, left: 18.w, right: 18.w),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(24.w)),
      padding: EdgeInsets.symmetric(horizontal: 32.w),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          SizedBox(height: 12.w),
          // 顶部指示器
          Container(
            width: 48.w,
            height: 5.w,
            decoration: BoxDecoration(
              color: AppColor.colorF5F5F5,
              borderRadius: BorderRadius.circular(50.w),
            ),
          ),
          SizedBox(height: 16.w),

          if (topWidget != null)
            topWidget!.marginOnly(bottom: 32.w),

          // 标题
          Text(
            title,
            style: titleTextStyle ??
                TextStyle(
                  fontFamily: 'Urbanist',
                  fontSize: 16.sp,
                  fontWeight: FontWeight.bold,
                  color: AppColor.color0C0A09,
                ),
            textAlign: TextAlign.center,
          ),

          SizedBox(height: titleMessagePadding.w),
          // 内容区域
          if (bodyWidget != null)
            bodyWidget!
          else if (message != null)
            Text(
              message!,
              style: TextStyle(
                fontSize: 14.sp,
                color: AppColor.color48484A,
              ),
              textAlign: messageTextAlign ?? TextAlign.center,
            ),
          SizedBox(height: 24.w),
          // 确认按钮

          showCancel
              ? Row(
                  children: [
                    Expanded(
                        child: CommonButton(
                      title: cancelText ?? 'Cancel',
                      type: ButtonType.secondary,
                      onClick: () {
                        if (autoDismiss) {
                          Get.back(result: true);
                        }
                        // if (onSure != null) {
                        onCancel?.call();
                        // }
                      },
                    )),
                    12.horizontalSpace,
                    Expanded(
                        child: CommonButton(
                      title: sureText ?? 'Confirm',
                      onClick: () {
                        if (autoDismiss) {
                          Get.back(result: true);
                        }
                        // if (onSure != null) {
                        onSure?.call();
                        // }
                      },
                    )),
                    12.horizontalSpace,
                  ],
                )
              : CommonButton.expend(
                  title: sureText ?? 'Confirm',
                  onClick: () {
                    if (autoDismiss) {
                      Get.back(result: true);
                    }
                    // if (onSure != null) {
                    onSure?.call();
                    // }
                  },
                ),
          SizedBox(height: 24.w),
        ],
      ),
    );
  }
}
